package com.rpframework.website.device.act.api;

import java.sql.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.rpframework.core.BaseAct;
import com.rpframework.utils.Pager;
import com.rpframework.website.device.domain.GoodsPro;
import com.rpframework.website.device.domain.GoodsProStockRecord;
import com.rpframework.website.device.domain.User;
import com.rpframework.website.device.exception.APICodeException;
import com.rpframework.website.device.service.GoodsProService;
import com.rpframework.website.device.service.GoodsProStockRecordService;

/**
 * 商品模块接口
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/api/goodspro")
public class ApiGoodsStockRecord extends BaseAct {
	@Resource GoodsProStockRecordService service;
	@Resource GoodsProService gsService;

	
		/**
		 * 
		 */
		@RequestMapping(value="/stockin",produces = "application/json; charset=utf-8")
		public @ResponseBody String Stockin(
				
				@RequestParam(value = "callback",required = false ) String callback,
				@RequestParam(value = "name",required = true ) String name,//商品名
				@RequestParam(value = "goodsModel",required = true ) String goodsModel,//商品型号
				@RequestParam(value = "brand",required = true ) Integer brand,//商品品牌
				@RequestParam(value = "amount",required = true ) Integer amount,//出入库数量 
				HttpSession session
				){
			JsonObject json = new JsonObject();
			User user=getSessionUser(session);
			if(user==null){
				throw new APICodeException(-4, "你还没登陆!");
			}
			
			List<GoodsPro> goodsList=gsService.getGoods(name,goodsModel,brand);
			if(goodsList.size()>0){
				GoodsPro gs=goodsList.get(0);
				GoodsProStockRecord r=new GoodsProStockRecord();
				r.setUserId(user.getId());
				r.setGoodsProId(gs.getId());
				r.setAmount(amount);
				r.setCreateTime(System.currentTimeMillis()/1000);
				
				boolean b=service.doSave(r);
				
				if(b){json.addProperty("msg", "入库成功");}
				
			}
			else{json.addProperty("msg", "无此产品，无法入库");}
			
			if(StringUtils.isNotBlank(callback))	return (callback + "(" + json + ")");
			return   ""+json  ;
		}
		
		
		
		@RequestMapping(value="/stockinByGoodsProId",produces = "application/json; charset=utf-8")
		public @ResponseBody String StockinById(
				
				@RequestParam(value = "callback",required = false ) String callback,
				@RequestParam(value = "goodsProId",required = true ) Integer goodsProId,//商品名
				
				@RequestParam(value = "amount",required = true ) Integer amount,//出入库数量 
				HttpSession session
				){
			JsonObject json = new JsonObject();
			User user=getSessionUser(session);
			if(user==null){
				throw new APICodeException(-4, "你还没登陆!");
			}
			
			GoodsProStockRecord r =new GoodsProStockRecord();
			r.setUserId(user.getId());
			r.setGoodsProId(goodsProId);
			r.setAmount(amount);
			r.setCreateTime(System.currentTimeMillis()/1000);
			boolean b=service.doSave(r);
			if(b){json.addProperty("msg", "入库成功");}
			if(StringUtils.isNotBlank(callback))	return (callback + "(" + json + ")");
			return   ""+json  ;
		}
		
		
		
		@RequestMapping(value="/stockout",produces = "application/json; charset=utf-8")
		public @ResponseBody String Stockout(
				
				@RequestParam(value = "callback",required = false ) String callback,
				@RequestParam(value = "name",required = true ) String name,//商品名
				@RequestParam(value = "goodsModel",required = true ) String goodsModel,//商品型号
				@RequestParam(value = "brand",required = true ) Integer brand,//商品品牌
				@RequestParam(value = "amount",required = true ) Integer amount,//出入库数量 
				HttpSession session
				){
			JsonObject json = new JsonObject();
			User user=getSessionUser(session);
			if(user==null){
				throw new APICodeException(-4, "你还没登陆!");
			}
			
			
			
			List<GoodsPro> goodsList=gsService.getGoods(name,goodsModel,brand);
			if(goodsList.size()==0){
				json.addProperty("msg", "您的产品库存中无此产品，请选择其他产品");
				if(StringUtils.isNotBlank(callback))	return (callback + "(" + json + ")");
				return   ""+json  ;
			}
			else{
				
				GoodsPro gs=goodsList.get(0);
				GoodsProStockRecord r=new GoodsProStockRecord();
				r.setUserId(user.getId());
				r.setGoodsProId(gs.getId());
				r.setAmount(-amount.intValue());
				r.setCreateTime(System.currentTimeMillis()/1000);
				
				boolean b=service.doSave(r);
				
				if(b){json.addProperty("msg", "出库成功");}
				else{json.addProperty("msg", "库存不足,请确认您有足够的库存");}
				
				if(StringUtils.isNotBlank(callback))	return (callback + "(" + json + ")");
				return   ""+json  ;
				
				
			}
			
		}
		
		
		
		
		@RequestMapping(value="/statistics",produces = "application/json; charset=utf-8")
		public @ResponseBody String Create2(
				@RequestParam(value = "callback",required = false ) String callback,
				HttpSession session
				){
			JsonObject json = new JsonObject();
			User user=getSessionUser(session);
			if(user==null){
				throw new APICodeException(-4, "你还没登陆!");
			}
			Integer total = service.getTotalProductType(user.getId());
			json.addProperty("total", total);
			if(StringUtils.isNotBlank(callback))
			return (callback + "(" + json + ")");
			return   ""+json  ;
		}
		
		
		@RequestMapping(value="/user/listrecord",produces = "application/json; charset=utf-8")
		public @ResponseBody String listoneWithSum(@RequestParam(value="pager",required = false ) Pager<GoodsProStockRecord> pager,
				@RequestParam(value="pageSize",required = false ) Integer pageSize,
				@RequestParam(value="category",required = false ) String category,/*1.冷鲜食品  2.休闲食品3.奶酒饮料4.粮油副食5.清洁用品6.个人护理7.生活日用8.母婴用品9.其它*/
				@RequestParam(value="label",required = false ) String label,/*标签 1.热门推荐 2.精品推荐 3.促销专区 4.热卖榜单*/  
				@RequestParam(value="state",required = false ) String state,/*状态 1.正常 2.禁用*/
				@RequestParam(value="brand",required = false ) String brand,/*品牌*/
				@RequestParam(value = "callback",required = false ) String callback,
				HttpSession session){
			User user = getSessionUser(session);
			if(user==null){
				throw new APICodeException(-4, "您尚未登录!");
			}
			if(pager==null){
				pager=new Pager<GoodsProStockRecord>();
			}
			if(pageSize!=null)pager.setPageSize(pageSize);
			if(StringUtils.isNotBlank(user.getId().toString()))pager.getSearchMap().put("userId", user.getId().toString());
			if(StringUtils.isNotBlank(category))pager.getSearchMap().put("category", category);
			if(StringUtils.isNotBlank(label))pager.getSearchMap().put("label", label);
			if(StringUtils.isNotBlank(state))pager.getSearchMap().put("state", state);
			if(StringUtils.isNotBlank(brand))pager.getSearchMap().put("brand", brand);
			pager = service.getPager(pager);
			JsonObject json=new JsonObject();
			json.addProperty("totalPages", pager.getTotalPages());
			json.addProperty("currentPage", pager.getCurrentPage());
			json.addProperty("totalCount", pager.getTotalCount());
			List<GoodsProStockRecord> list=pager.getItemList();
			if(list!=null && list.size()>0){
			JsonArray array=new JsonArray();
				for(GoodsProStockRecord t : list){
					JsonObject obj = new JsonObject();
					
					long time=t.getCreateTime()*1000;
					DateFormat format= new SimpleDateFormat("yyyy-MM-dd HH:mm");
					String dataString=format.format(new Date(time));
					Integer goodsProId=t.getGoodsProId();
					GoodsPro goodsPro=(GoodsPro)gsService.select(goodsProId);
					obj.addProperty("id", t.getId());//库存记录Id
					obj.addProperty("dataString", dataString);//库存记录时间yyyy-MM-dd hh:mm
					obj.addProperty("name", goodsPro.getName());//产品名
					obj.addProperty("amount", t.getAmount());//产品出入库存数量
					
					array.add(obj);
				}
				json.add("arrays", array);
			}
			if(StringUtils.isNotBlank(callback))	return (callback + "(" + json + ")");
			return   ""+json  ;
		}
		
		
		
		@RequestMapping(value="/user/listrecordByTime",produces = "application/json; charset=utf-8")
		public @ResponseBody String searchRecordByTime(@RequestParam(value="pager",required = false ) Pager<GoodsProStockRecord> pager,
				@RequestParam(value="pageSize",required = false ) Integer pageSize,
				@RequestParam(value="category",required = false ) String category,/*1.冷鲜食品  2.休闲食品3.奶酒饮料4.粮油副食5.清洁用品6.个人护理7.生活日用8.母婴用品9.其它*/
				@RequestParam(value="label",required = false ) String label,/*标签 1.热门推荐 2.精品推荐 3.促销专区 4.热卖榜单*/  
				@RequestParam(value="state",required = false ) String state,/*状态 1.正常 2.禁用*/
				@RequestParam(value="brand",required = false ) String brand,/*品牌*/
				@RequestParam(value="year1",required = false ) String year1,/*查询开始时间年部分*/
				@RequestParam(value="day1",required = false ) String day1,/*查询开始时间月日部分*/
				@RequestParam(value="year2",required = false ) String year2,/*查询结束时间年部分*/
				@RequestParam(value="day2",required = false ) String day2,/*查询结束时间月日部分*/
				@RequestParam(value = "callback",required = false ) String callback,
				HttpSession session){
			User user = getSessionUser(session);
			if(user==null){
				throw new APICodeException(-4, "您尚未登录!");
			}
			
			Integer userId=user.getId();

			if(pager==null){
				pager=new Pager<GoodsProStockRecord>();
			}
			if(pageSize!=null)pager.setPageSize(pageSize);
			
			Integer time1,time2;
			try {
				time1= DTTimeUtils.StringToTime(year1, day1);
				time2= DTTimeUtils.StringToTime(year2, day2);
			} catch (ParseException e) {
				
				throw new APICodeException(-100, "日期参数非法!");
				
			}
			
			
			
			
			if(pageSize!=null)pager.setPageSize(pageSize);
			
			if(StringUtils.isNotBlank(userId.toString()))pager.getSearchMap().put("userId", userId.toString());
			if(StringUtils.isNotBlank(time1.toString()))pager.getSearchMap().put("time1", time1.toString());
			if(StringUtils.isNotBlank(time2.toString()))pager.getSearchMap().put("time2", time2.toString());
			if(StringUtils.isNotBlank(state))pager.getSearchMap().put("state", state);
			
	         pager=service.searchRecordByTime(pager);
	         List<GoodsProStockRecord> list=pager.getItemList();
			

			
			JsonObject json=new JsonObject();
			
			
			
			json.addProperty("totalPages", pager.getTotalPages());
			json.addProperty("currentPage", pager.getCurrentPage());
			json.addProperty("totalCount", pager.getTotalCount());
			
			if(list!=null && list.size()>0){
			JsonArray array=new JsonArray();
				for(GoodsProStockRecord t : list){
					JsonObject obj = new JsonObject();
					
					long time=t.getCreateTime()*1000;
					DateFormat format= new SimpleDateFormat("yyyy-MM-dd HH:mm");
					String dataString=format.format(new Date(time));
					Integer goodsProId=t.getGoodsProId();
					GoodsPro goodsPro=(GoodsPro)gsService.select(goodsProId);
					obj.addProperty("id", t.getId());//库存记录Id
					obj.addProperty("dataString", dataString);//库存记录时间yyyy-MM-dd hh:mm
					obj.addProperty("name", goodsPro.getName());//产品名
					obj.addProperty("amount", t.getAmount());//产品出入库存数量
					
					array.add(obj);
				}
				json.add("arrays", array);
			}
			if(StringUtils.isNotBlank(callback))	return (callback + "(" + json + ")");
			return   ""+json  ;
		}
		
		
		
		@RequestMapping(value="/user/listinrecordByTime",produces = "application/json; charset=utf-8")
		public @ResponseBody String searchInRecordByTime(@RequestParam(value="pager",required = false ) Pager<GoodsProStockRecord> pager,
				@RequestParam(value="pageSize",required = false ) Integer pageSize,
				@RequestParam(value="category",required = false ) String category,/*1.冷鲜食品  2.休闲食品3.奶酒饮料4.粮油副食5.清洁用品6.个人护理7.生活日用8.母婴用品9.其它*/
				@RequestParam(value="label",required = false ) String label,/*标签 1.热门推荐 2.精品推荐 3.促销专区 4.热卖榜单*/  
				@RequestParam(value="state",required = false ) String state,/*状态 1.正常 2.禁用*/
				@RequestParam(value="brand",required = false ) String brand,/*品牌*/
				@RequestParam(value="year1",required = false ) String year1,/*查询开始时间年部分*/
				@RequestParam(value="day1",required = false ) String day1,/*查询开始时间月日部分*/
				@RequestParam(value="year2",required = false ) String year2,/*查询结束时间年部分*/
				@RequestParam(value="day2",required = false ) String day2,/*查询结束时间月日部分*/
				@RequestParam(value = "callback",required = false ) String callback,
				HttpSession session){
			User user = getSessionUser(session);
			if(user==null){
				throw new APICodeException(-4, "您尚未登录!");
			}
			
			Integer userId=user.getId();

			if(pager==null){
				pager=new Pager<GoodsProStockRecord>();
			}
			if(pageSize!=null)pager.setPageSize(pageSize);
			
			Integer time1,time2;
			try {
				time1= DTTimeUtils.StringToTime(year1, day1);
				time2= DTTimeUtils.StringToTime(year2, day2);
			} catch (ParseException e) {
				
				throw new APICodeException(-100, "日期参数非法!");
				
			}
			
			
			
			
			if(pageSize!=null)pager.setPageSize(pageSize);
			
			if(StringUtils.isNotBlank(userId.toString()))pager.getSearchMap().put("userId", userId.toString());
			if(StringUtils.isNotBlank(time1.toString()))pager.getSearchMap().put("time1", time1.toString());
			if(StringUtils.isNotBlank(time2.toString()))pager.getSearchMap().put("time2", time2.toString());
			if(StringUtils.isNotBlank(state))pager.getSearchMap().put("state", state);
			
	         pager=service.searchInRecordByTime(pager);
	         List<GoodsProStockRecord> list=pager.getItemList();
			

			
			JsonObject json=new JsonObject();
			
			
			
			json.addProperty("totalPages", pager.getTotalPages());
			json.addProperty("currentPage", pager.getCurrentPage());
			json.addProperty("totalCount", pager.getTotalCount());
			
			if(list!=null && list.size()>0){
			JsonArray array=new JsonArray();
				for(GoodsProStockRecord t : list){
					JsonObject obj = new JsonObject();
					
					long time=t.getCreateTime()*1000;
					DateFormat format= new SimpleDateFormat("yyyy-MM-dd HH:mm");
					String dataString=format.format(new Date(time));
					Integer goodsProId=t.getGoodsProId();
					GoodsPro goodsPro=(GoodsPro)gsService.select(goodsProId);
					obj.addProperty("id", t.getId());//库存记录Id
					obj.addProperty("dataString", dataString);//库存记录时间yyyy-MM-dd hh:mm
					obj.addProperty("name", goodsPro.getName());//产品名
					obj.addProperty("amount", t.getAmount());//产品出入库存数量
					
					array.add(obj);
				}
				json.add("arrays", array);
			}
			if(StringUtils.isNotBlank(callback))	return (callback + "(" + json + ")");
			return   ""+json  ;
		}
		
		
		
		
		
		
		@RequestMapping(value="/user/listoutrecordByTime",produces = "application/json; charset=utf-8")
		public @ResponseBody String searchOutRecordByTime(@RequestParam(value="pager",required = false ) Pager<GoodsProStockRecord> pager,
				@RequestParam(value="pageSize",required = false ) Integer pageSize,
				@RequestParam(value="category",required = false ) String category,/*1.冷鲜食品  2.休闲食品3.奶酒饮料4.粮油副食5.清洁用品6.个人护理7.生活日用8.母婴用品9.其它*/
				@RequestParam(value="label",required = false ) String label,/*标签 1.热门推荐 2.精品推荐 3.促销专区 4.热卖榜单*/  
				@RequestParam(value="state",required = false ) String state,/*状态 1.正常 2.禁用*/
				@RequestParam(value="brand",required = false ) String brand,/*品牌*/
				@RequestParam(value="year1",required = false ) String year1,/*查询开始时间年部分*/
				@RequestParam(value="day1",required = false ) String day1,/*查询开始时间月日部分*/
				@RequestParam(value="year2",required = false ) String year2,/*查询结束时间年部分*/
				@RequestParam(value="day2",required = false ) String day2,/*查询结束时间月日部分*/
				@RequestParam(value = "callback",required = false ) String callback,
				HttpSession session){
			User user = getSessionUser(session);
			if(user==null){
				throw new APICodeException(-4, "您尚未登录!");
			}
			
			Integer userId=user.getId();

			if(pager==null){
				pager=new Pager<GoodsProStockRecord>();
			}
			if(pageSize!=null)pager.setPageSize(pageSize);
			
			Integer time1,time2;
			try {
				time1= DTTimeUtils.StringToTime(year1, day1);
				time2= DTTimeUtils.StringToTime(year2, day2);
			} catch (ParseException e) {
				
				throw new APICodeException(-100, "日期参数非法!");
				
			}
			
			
			
			
			if(pageSize!=null)pager.setPageSize(pageSize);
			
			if(StringUtils.isNotBlank(userId.toString()))pager.getSearchMap().put("userId", userId.toString());
			if(StringUtils.isNotBlank(time1.toString()))pager.getSearchMap().put("time1", time1.toString());
			if(StringUtils.isNotBlank(time2.toString()))pager.getSearchMap().put("time2", time2.toString());
			if(StringUtils.isNotBlank(state))pager.getSearchMap().put("state", state);
			
	         pager=service.searchOutRecordByTime(pager);
	         List<GoodsProStockRecord> list=pager.getItemList();
			

			
			JsonObject json=new JsonObject();
			
			
			
			json.addProperty("totalPages", pager.getTotalPages());
			json.addProperty("currentPage", pager.getCurrentPage());
			json.addProperty("totalCount", pager.getTotalCount());
			
			if(list!=null && list.size()>0){
			JsonArray array=new JsonArray();
				for(GoodsProStockRecord t : list){
					JsonObject obj = new JsonObject();
					
					long time=t.getCreateTime()*1000;
					DateFormat format= new SimpleDateFormat("yyyy-MM-dd HH:mm");
					String dataString=format.format(new Date(time));
					Integer goodsProId=t.getGoodsProId();
					GoodsPro goodsPro=(GoodsPro)gsService.select(goodsProId);
					obj.addProperty("id", t.getId());//库存记录Id
					obj.addProperty("dataString", dataString);//库存记录时间yyyy-MM-dd hh:mm
					obj.addProperty("name", goodsPro.getName());//产品名
					obj.addProperty("amount", t.getAmount());//产品出入库存数量
					
					array.add(obj);
				}
				json.add("arrays", array);
			}
			if(StringUtils.isNotBlank(callback))	return (callback + "(" + json + ")");
			return   ""+json  ;
		}
		
		
		
		
		
		
		
		
		
		
		
		@RequestMapping(value="/user/listInRecordThisMonth",produces = "application/json; charset=utf-8")
		public @ResponseBody String searchInRecordThisMonth(@RequestParam(value="pager",required = false ) Pager<GoodsProStockRecord> pager,
				@RequestParam(value="pageSize",required = false ) Integer pageSize,
				@RequestParam(value="category",required = false ) String category,/*1.冷鲜食品  2.休闲食品3.奶酒饮料4.粮油副食5.清洁用品6.个人护理7.生活日用8.母婴用品9.其它*/
				@RequestParam(value="label",required = false ) String label,/*标签 1.热门推荐 2.精品推荐 3.促销专区 4.热卖榜单*/  
				@RequestParam(value="state",required = false ) String state,/*状态 1.正常 2.禁用*/
				@RequestParam(value = "callback",required = false ) String callback,
				HttpSession session){
			User user = getSessionUser(session);
			if(user==null){
				throw new APICodeException(-4, "您尚未登录!");
			}
			
			Integer userId=user.getId();

			if(pager==null){
				pager=new Pager<GoodsProStockRecord>();
			}
			if(pageSize!=null)pager.setPageSize(pageSize);
			
			Integer time1,time2;
			try {
				time1= DTTimeUtils.monthFirstDayTime();
				time2= DTTimeUtils.nowTime();
			} catch (ParseException e) {
				
				throw new APICodeException(-100, "日期参数非法!");
				
			}
			
			
			
			
			if(pageSize!=null)pager.setPageSize(pageSize);
			
			if(StringUtils.isNotBlank(userId.toString()))pager.getSearchMap().put("userId", userId.toString());
			if(StringUtils.isNotBlank(time1.toString()))pager.getSearchMap().put("time1", time1.toString());
			if(StringUtils.isNotBlank(time2.toString()))pager.getSearchMap().put("time2", time2.toString());
			if(StringUtils.isNotBlank(state))pager.getSearchMap().put("state", state);
			
	         pager=service.searchInRecordByTime(pager);
	         List<GoodsProStockRecord> list=pager.getItemList();
			

			
			JsonObject json=new JsonObject();
			
			
			
			json.addProperty("totalPages", pager.getTotalPages());
			json.addProperty("currentPage", pager.getCurrentPage());
			json.addProperty("totalCount", pager.getTotalCount());
			
			if(list!=null && list.size()>0){
			JsonArray array=new JsonArray();
				for(GoodsProStockRecord t : list){
					JsonObject obj = new JsonObject();
					
					long time=t.getCreateTime()*1000;
					DateFormat format= new SimpleDateFormat("yyyy-MM-dd HH:mm");
					String dataString=format.format(new Date(time));
					Integer goodsProId=t.getGoodsProId();
					GoodsPro goodsPro=(GoodsPro)gsService.select(goodsProId);
					obj.addProperty("id", t.getId());//库存记录Id
					obj.addProperty("dataString", dataString);//库存记录时间yyyy-MM-dd hh:mm
					obj.addProperty("name", goodsPro.getName());//产品名
					obj.addProperty("amount", t.getAmount());//产品出入库存数量
					
					array.add(obj);
				}
				json.add("arrays", array);
			}
			if(StringUtils.isNotBlank(callback))	return (callback + "(" + json + ")");
			return   ""+json  ;
		}
		
		
		
		
		
		@RequestMapping(value="/user/listOutRecordThisMonth",produces = "application/json; charset=utf-8")
		public @ResponseBody String searchOutRecordThisMonth(@RequestParam(value="pager",required = false ) Pager<GoodsProStockRecord> pager,
				@RequestParam(value="pageSize",required = false ) Integer pageSize,
				@RequestParam(value="category",required = false ) String category,/*1.冷鲜食品  2.休闲食品3.奶酒饮料4.粮油副食5.清洁用品6.个人护理7.生活日用8.母婴用品9.其它*/
				@RequestParam(value="label",required = false ) String label,/*标签 1.热门推荐 2.精品推荐 3.促销专区 4.热卖榜单*/  
				@RequestParam(value="state",required = false ) String state,/*状态 1.正常 2.禁用*/
				@RequestParam(value = "callback",required = false ) String callback,
				HttpSession session){
			User user = getSessionUser(session);
			if(user==null){
				throw new APICodeException(-4, "您尚未登录!");
			}
			
			Integer userId=user.getId();

			if(pager==null){
				pager=new Pager<GoodsProStockRecord>();
			}
			if(pageSize!=null)pager.setPageSize(pageSize);
			
			Integer time1,time2;
			try {
				time1= DTTimeUtils.monthFirstDayTime();
				time2= DTTimeUtils.nowTime();
			} catch (ParseException e) {
				
				throw new APICodeException(-100, "日期参数非法!");
				
			}
			
			
			
			
			if(pageSize!=null)pager.setPageSize(pageSize);
			
			if(StringUtils.isNotBlank(userId.toString()))pager.getSearchMap().put("userId", userId.toString());
			if(StringUtils.isNotBlank(time1.toString()))pager.getSearchMap().put("time1", time1.toString());
			if(StringUtils.isNotBlank(time2.toString()))pager.getSearchMap().put("time2", time2.toString());
			if(StringUtils.isNotBlank(state))pager.getSearchMap().put("state", state);
			
	         pager=service.searchOutRecordByTime(pager);
	         List<GoodsProStockRecord> list=pager.getItemList();
			

			
			JsonObject json=new JsonObject();
			
			
			
			json.addProperty("totalPages", pager.getTotalPages());
			json.addProperty("currentPage", pager.getCurrentPage());
			json.addProperty("totalCount", pager.getTotalCount());
			
			if(list!=null && list.size()>0){
			JsonArray array=new JsonArray();
				for(GoodsProStockRecord t : list){
					JsonObject obj = new JsonObject();
					
					long time=t.getCreateTime()*1000;
					DateFormat format= new SimpleDateFormat("yyyy-MM-dd HH:mm");
					String dataString=format.format(new Date(time));
					Integer goodsProId=t.getGoodsProId();
					GoodsPro goodsPro=(GoodsPro)gsService.select(goodsProId);
					obj.addProperty("id", t.getId());//库存记录Id
					obj.addProperty("dataString", dataString);//库存记录时间yyyy-MM-dd hh:mm
					obj.addProperty("name", goodsPro.getName());//产品名
					obj.addProperty("amount", t.getAmount());//产品出入库存数量
					
					array.add(obj);
				}
				json.add("arrays", array);
			}
			if(StringUtils.isNotBlank(callback))	return (callback + "(" + json + ")");
			return   ""+json  ;
		}
		
		
		
		
}
